#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
const int N = 20;
char a[N][N],b[N][N],r[N][N];
int n;
bool work1()
{
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			r[j][n - i + 1] = a[i][j];

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			if (r[i][j] != b[i][j])
				return 0;
	return 1;
}
bool work2()
{
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			r[n - i + 1][n - j + 1] = a[i][j];
	
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			if (r[i][j] != b[i][j])
				return 0;
	return 1;
}
bool work3()
{
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			r[n - j + 1][i] = a[i][j];
	
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			if (r[i][j] != b[i][j])
				return 0;
	return 1;
}
bool work4()
{
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			r[i][n - j + 1] = a[i][j];
	
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			if (r[i][j] != b[i][j])
				return 0;
	return 1;
}
bool work5()
{
	work4();
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			a[i][j] = r[i][j];
	if (work1())
		return 1;
	if (work2())
		return 1;
	if (work3())
		return 1;
	return 0;
}
bool work6()
{
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			if (a[i][j] != b[i][j])
				return 0;
	return 1;
}

void solve()
{
	if (work1())
	{
		cout << 1 << endl;
		return;
	}
	if (work2())
	{
		cout << 2 << endl;
		return;
	}
	if (work3())
	{
		cout << 3 << endl;
		return;
	}
	if (work4())
	{
		cout << 4 << endl;
		return;
	}
	if (work5())
	{
		cout << 5 << endl;
		return;
	}
	if (work6())
	{
		cout << 6 << endl;
		return;
	}
	cout << 7 << endl;
	return;
}
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			cin >> a[i][j];
	
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			cin >> b[i][j];

	solve();

	return 0;
}